using MicroMsg.Common.Utils;
using MicroMsg.UI.Page;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
namespace MicroMsg.UI.UserContrl
{
	public class ScrollTextBlock : UserControl
	{
		private const uint cNAniT = 40u;
		private const double cDAniL = 0.2;
		private bool mBIsTxtConFirstLoaded = true;
		private bool mBIsScrollEnable;
		private bool mBIsFirstLoaded = true;
		private Point mPMStart = new Point(-1.0, -1.0);
		private DispatcherTimer mTimerIconMore;
		private bool isShownMoreIcon;
		private double mDMoreIconOrginOpacity;
		private DispatcherTimer mTimer;
		private double mNAniL = 0.2;
		public static DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(ScrollTextBlock), new PropertyMetadata(null, new PropertyChangedCallback(ScrollTextBlock.strTitlePropertyChanged)));
		public static DependencyProperty FontSizeProperty = DependencyProperty.Register("FontSize", typeof(string), typeof(ScrollTextBlock), new PropertyMetadata(null, new PropertyChangedCallback(ScrollTextBlock.OnFontSizePropertyChanged)));
		internal UserControl @this;
		internal Grid LayoutRoot;
		internal ScrollViewer scrollViewer_0;
		internal EmojiText txtContent;
		internal Image imgMore;
		private bool _contentLoaded;
		public string Text
		{
			get
			{
				return (string)base.GetValue(ScrollTextBlock.TextProperty);
			}
			set
			{
				base.SetValue(ScrollTextBlock.TextProperty, value);
			}
		}
		public string FontSize
		{
			get
			{
				return (string)base.GetValue(ScrollTextBlock.FontSizeProperty);
			}
			set
			{
				base.SetValue(ScrollTextBlock.FontSizeProperty, value);
			}
		}
		public ScrollTextBlock()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Control_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Control_Unloaded));
			this.txtContent.add_Loaded(new RoutedEventHandler(this.txtContent_Loaded));
		}
		private void txtContent_Loaded(object sender, RoutedEventArgs e)
		{
			if (!this.mBIsTxtConFirstLoaded)
			{
				return;
			}
			this.mBIsTxtConFirstLoaded = false;
		}
		private void Control_Loaded(object sender, RoutedEventArgs e)
		{
			Deployment.get_Current().get_Dispatcher().BeginInvoke(delegate
			{
				this.startScrollAni();
			});
		}
		private void Control_Unloaded(object sender, RoutedEventArgs e)
		{
			this.pauseScrollAni();
		}
		private void startTimerIconMore()
		{
			this.mTimerIconMore = new DispatcherTimer();
			this.mTimerIconMore.set_Interval(TimeSpan.FromMilliseconds(40.0));
			this.mTimerIconMore.add_Tick(new EventHandler(this.mTimerIconMore_Tick));
			this.mTimerIconMore.Start();
		}
		private void mTimerIconMore_Tick(object sender, EventArgs e)
		{
			this.refreshMoreIcon(0.0);
		}
		private void stopTimerIconMore()
		{
			this.mTimerIconMore.remove_Tick(new EventHandler(this.mTimerIconMore_Tick));
			this.mTimerIconMore.Stop();
			this.mTimerIconMore = null;
		}
		private void sv_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
			this.stopScrollAni();
			this.mPMStart = e.get_ManipulationOrigin();
			this.showMoreIcon();
		}
		private void sv_MouseMove(object sender, MouseEventArgs e)
		{
		}
		private void sv_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
			this.hideMoreIcon();
			this.stopTimerIconMore();
		}
		private void sv_MouseLeave(object sender, MouseEventArgs e)
		{
		}
		private void sv_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			this.hideMoreIcon();
		}
		private void sv_MouseWheel(object sender, MouseWheelEventArgs e)
		{
		}
		private void getHOffset()
		{
			double arg_0B_0 = this.scrollViewer_0.get_HorizontalOffset();
		}
		public void Refresh()
		{
			this.txtContent.Text = this.Text;
			try
			{
				base.UpdateLayout();
			}
			catch (Exception ex)
			{
				Log.smethod_5("ScrollTextBlock", ex.get_Message());
			}
			this.txtContent.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
			base.set_MinHeight(this.txtContent.get_DesiredSize().get_Height());
			if (this.txtContent.get_DesiredSize().get_Width() < base.get_MaxWidth() - 0.1)
			{
				this.scrollViewer_0.set_IsEnabled(false);
				this.mBIsScrollEnable = false;
				this.imgMore.set_Visibility(1);
				return;
			}
			this.mBIsScrollEnable = true;
			this.scrollViewer_0.set_IsEnabled(true);
			this.scrollViewer_0.set_MaxWidth(base.get_MaxWidth() - 14.0);
			this.scrollViewer_0.set_Width(base.get_Width() - 14.0);
			base.set_MaxWidth(base.get_MaxWidth() + 0.0);
			base.set_Width(base.get_Width() + 0.0);
			this.imgMore.set_Visibility(0);
			this.showMoreIcon();
			base.UpdateLayout();
		}
		private void showMoreIcon()
		{
			this.isShownMoreIcon = true;
			if (this.imgMore.get_Source() == null)
			{
				if (MMTheme.IsCoolBlackTheme())
				{
					this.imgMore.set_Source(new BitmapImage(new Uri("/Resource/Img/CommonUse/scrolltextmore_icon.png", 2)));
					return;
				}
				this.imgMore.set_Source(new BitmapImage(new Uri("/Resource/Img/CommonUse/scrolltextmore_icon_light.png", 2)));
			}
		}
		private void refreshMoreIcon(double dOffset)
		{
			if (!this.isShownMoreIcon)
			{
				return;
			}
			double num = 1.0 - (this.scrollViewer_0.get_HorizontalOffset() - dOffset * 0.0) / (this.scrollViewer_0.get_ExtentWidth() - this.scrollViewer_0.get_ActualWidth());
			if (num < 0.0)
			{
				num = 0.0;
			}
			if (num > 1.0)
			{
				num = 1.0;
			}
			this.imgMore.set_Opacity(num);
		}
		private void hideMoreIcon()
		{
			this.isShownMoreIcon = false;
			this.imgMore.set_Opacity(0.0);
		}
		private void startScrollAni()
		{
		}
		private void mTimer_Tick(object sender, EventArgs e)
		{
			if (this.scrollViewer_0.get_ExtentWidth() < this.scrollViewer_0.get_ActualWidth() + 0.1)
			{
				this.stopScrollAni();
				return;
			}
			double num = this.scrollViewer_0.get_HorizontalOffset() + this.mNAniL;
			if (num >= this.scrollViewer_0.get_ExtentWidth() - this.scrollViewer_0.get_ActualWidth() - -1.0)
			{
				num = this.scrollViewer_0.get_ExtentWidth() - this.scrollViewer_0.get_ActualWidth();
				this.mNAniL = -0.2;
			}
			else
			{
				if (num < 0.1)
				{
					num = 0.0;
					this.mNAniL = 0.2;
				}
			}
			this.scrollViewer_0.ScrollToHorizontalOffset(num);
		}
		private void pauseScrollAni()
		{
			if (this.mTimer != null)
			{
				this.mTimer.Stop();
			}
		}
		private void stopScrollAni()
		{
			if (this.mTimer != null)
			{
				this.mTimer.Stop();
				this.mTimer = null;
			}
		}
		private static void strTitlePropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == ScrollTextBlock.TextProperty)
			{
				ScrollTextBlock scrollTextBlock = dependencyObject_0 as ScrollTextBlock;
				scrollTextBlock.Refresh();
			}
		}
		private static void OnFontSizePropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == ScrollTextBlock.FontSizeProperty)
			{
				(dependencyObject_0 as ScrollTextBlock).FontSizePropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void FontSizePropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_OldValue() != dependencyPropertyChangedEventArgs_0.get_NewValue())
			{
				this.txtContent.FontSize = double.Parse(this.FontSize);
				if (!string.IsNullOrEmpty(this.Text))
				{
					this.Refresh();
				}
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/CommonUseControl/ScrollTextBlock.xaml", 2));
			this.@this = (UserControl)base.FindName("this");
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.scrollViewer_0 = (ScrollViewer)base.FindName("sv");
			this.txtContent = (EmojiText)base.FindName("txtContent");
			this.imgMore = (Image)base.FindName("imgMore");
		}
	}
}
